#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

struct A {
    int x;
};

__thread int count = 0;

void* add(void* arg) {
    static __thread struct A a = {0}; // g++编译可去掉struct

    int n = *(int*)arg;
    count += n;
    a.x += n;

    printf("%lu:%d %d\n", pthread_self(), count, a.x);
    return NULL;
}

int main() {
    pthread_t pid1, pid2;
    int n[] = {1, 2};

    pthread_create(&pid1, NULL, add, (void*)n);
    pthread_create(&pid2, NULL, add, (void*)(n+1));
    pthread_join(pid1, NULL);
    pthread_join(pid2, NULL);

    return 0;
}